<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>watch</title>
</head>

<body>
    <div id="app">
        <div>
            <div>
                <span>名：</span>
                <span>
                    <input type="text" v-model='firstName'>
                </span>
            </div>
            <div>
                <span>姓：</span>
                <span>
                    <input type="text" v-model='lastName'>
                </span>
            </div>
            <div>{{fullName}}</div>
        </div>
    </div>

    <script type="text/javascript" src="js/vue.js"></script>
    <script type="text/javascript">
        var vm = new Vue({
            el: '#app',
            data: {
                firstName: '',
                lastName: '',
                fullName: ''
            },
            // 侦听器侦听的是已经存在的属性
            watch: {
                firstName: function (val) {
                    this.fullName = this.lastName + val;
                },
                lastName: function (val) {
                    this.fullName = val + this.firstName;
                }
            }
        });
    </script>
</body>

</html>